package com.joshondesign.sdljava.demo;

import com.joshondesign.sdljava.SDLUtil;
import com.joshondesign.sdljava.SDL_Surface;
import com.joshondesign.sdljava.gfx.*;
import com.joshondesign.sdljava.gfx.effects.BrightnessFilter;
import com.joshondesign.sdljava.gfx.effects.SaturationFilter;

import java.io.File;

public class PhotoTest implements SDLUtil.InitCallback {

    public static void main(String ... args) {
        SDLUtil.init(new PhotoTest());
    }

    public void callback() throws Exception {
        Util.standard_init();
        SDLUtil.dumpInfo();
        SDL_Surface surface = Util.createResizableWindow(1024, 768);
        final Scene scene = new Scene(surface);
        scene.setBackgroundFill(SColor.BLACK);
        final Layer layer = new Layer(surface.getFormat());
        scene.add(layer);
        final SImage image = new SImage(new File("src/resources/andromeda.jpg"));


        final BrightnessFilter contrastFilter = new BrightnessFilter();
        final SliderNode slider = new SliderNode(scene);
        slider.onChange(new Callback(){
            public void call(Object o) {
                contrastFilter.setValue(2.0*(slider.getValue()-0.5));
            }
        });
        slider.setX(600).setY(10);


        final SaturationFilter saturationFilter = new SaturationFilter();
        final SliderNode s2 = new SliderNode(scene);
        s2.onChange(new Callback() {
            public void call(Object o) {
                saturationFilter.setValue(s2.getValue());
            }
        });
        s2.setX(600).setY(100);

        layer.add(new FilterNode(saturationFilter,new FilterNode(contrastFilter, image)));
        layer.add(new LabelNode()
            .setText("brightness")
            .setHAlign(LabelNode.HAlign.Right)
            .setTextColor(SColor.WHITE)
            .setX(590)
            .setY(35)
            );
        layer.add(new LabelNode()
            .setText("saturation")
            .setHAlign(LabelNode.HAlign.Right)
            .setTextColor(SColor.WHITE)
            .setX(590)
            .setY(135)
            );
        layer.add(slider);
        layer.add(s2);

        scene.setTargetFPS(60);
        scene.start();
    }

}
